package com.by.log.provider;

import com.by.log.Logger;
import com.by.log.handler.LogStorage;
import com.by.log.handler.LoggerProvider;
import com.by.log.handler.DefaultLogger;
import com.by.log.constants.LogLevel;

import java.util.concurrent.ConcurrentHashMap;

/**
 * 默认日志提供者实现
 */
public class DefaultLoggerProvider implements LoggerProvider {
    private final ConcurrentHashMap<String, Logger> loggerCache = new ConcurrentHashMap<>();

    @Override
    public Logger getLogger(Class<?> clazz, LogStorage storage) {
        return getLogger(clazz.getName(), storage);
    }

    @Override
    public Logger getLogger(String className, LogStorage logStorage) {
        DefaultLogger logger = new DefaultLogger(className, LogLevel.INFO, null);
        if (logStorage != null) {
            logger.setLogStorage(logStorage);
        }
        return logger;
    }
}